home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / comms / other / novia / commands / convert.c
C/C++ Source or Header  |  1999-12-06  |  3KB  |  105 lines

  1. #include <pragma/noviasys_lib.h>
  2. #include <pragma/exec_lib.h>
  3. #include <pragma/dos_lib.h>
  4. #include <exec/memory.h>
  5. #include <novia/cnet.h>
  6.  
  7. #define CNET_SUBBOARDS "sysdata:subboards3"
  8. #define _TEXT "data/_Text"
  9. #define _MESSAGE3 "data/_Message3"
  10. #define _HEADERS3 "data/_Headers3"
  11. #define _ITEMS3 "data/_Items3"
  12.  
  13. struct Library *NoviaSysBase = NULL;
  14.  
  15. void convert();
  16. PortData *cport;
  17.  
  18. void ioprintf(const char *string, ...)
  19. {
  20.     char *buffer=AllocVec(10000,MEMF_ANY|MEMF_CLEAR);
  21.     if (buffer)
  22.     {
  23.         vsprintf(buffer, string, unsigned int(&string + 1));
  24.         Writeio(buffer,-1);
  25.         FreeVec(buffer);
  26.     }
  27. }
  28.  
  29. void main( int argc, char **argv )
  30. {
  31.     if ((NoviaSysBase = OpenLibrary("noviasys.library",0)))
  32.     {
  33.         Task *mytask = (Task *)FindTask(NULL);
  34.         StrToLong(argv[1],(LONG *)&mytask->tc_UserData);
  35.         cport = (PortData *)mytask->tc_UserData;
  36.         convert();
  37.         CloseLibrary(NoviaSysBase);
  38.     }
  39. }
  40.  
  41. void convert()
  42. {
  43.     struct NewSubboardType *nst;
  44.     char buffer[256];
  45.     ULONG counter = 0;
  46.     ULONG    end      = 0;
  47.     ULONG    subboards = 0;
  48.     BPTR    mulder;
  49.     char *path = AllocVec(25600,MEMF_ANY|MEMF_CLEAR);
  50.     strcpy(path,"novia:sysdata/root");
  51.     ioprintf("\n");
  52.  
  53.     if ((mulder = Open(CNET_SUBBOARDS,MODE_OLDFILE)))                                        // Open subboards3     (cnet's subboard-table)
  54.     {
  55.         Seek(mulder,0,OFFSET_END);                                                                    // get size of cnet's subboard table
  56.         if ((end = Seek(mulder, 0 ,OFFSET_BEGINNING) / sizeof(NewSubboardType)))    // calculate number subboards
  57.         {
  58.             if ((nst = AllocVec(end * sizeof(NewSubboardType), MEMF_ANY)))                // allocate memory for subboad table
  59.             {
  60.                 Read(mulder,nst,end*sizeof(NewSubboardType));                                // read subboard table
  61.                 for (counter = 0; counter < end; counter++)
  62.                 {
  63.                     if (nst[counter].Parent == -1)
  64.                     {
  65. //                        if (nst[counter].Subdirectory)
  66.                         {
  67.                             ioprintf("Title: %s , Subboard %d\n",
  68.                                 nst[counter].Title,
  69.                                 nst[counter].Subdirectory);
  70.                             ndos_mkdir(nst[counter].Title,cport);
  71.                         }
  72.                         subboards++;
  73.                     }
  74.                 }
  75.                 for (counter = 0; counter < end; counter++)
  76.                 {
  77.                     ULONG counter2;
  78.                     for (counter2 = 0; counter2 < end; counter2++)
  79.                     {    
  80.                         if (nst[counter2].Parent == counter)
  81.                         {
  82. //                            if (nst[counter2].Subdirectory)
  83.                             {
  84.                                 ioprintf("Title: %s , Subboard %d\n",
  85.                                     nst[counter2].Title,
  86.                                     nst[counter2].Subdirectory);
  87.                                 ndos_mkdir(nst[counter2].Title,cport);
  88.                             }
  89.                             subboards++;
  90.                         }
  91.                     }
  92.                 }
  93.                 FreeVec(nst);
  94.             }
  95.         }
  96.         Close(mulder);
  97.         ioprintf(" subboard: %d end: %d\n",subboards,end);
  98.     }
  99.     else
  100.     {
  101.         ioprintf("Can't open: %s\n",CNET_SUBBOARDS);
  102.         exit(20);
  103.     }
  104. }
  105.